package com.soul.dubbo.api.mongo;

import com.soul.dubbo.api.db.QuestionnaireApi;
import com.soul.model.mongo.Questions;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author mdoya
 * @version 1.0
 * @description: 问卷实现类
 */
@Slf4j
@DubboService
public class QuestionnaireApiImpl implements QuestionnaireApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 查询试题编号 题目
     *
     * @param questionIds
     * @return
     */
    @Override
    public Map<String, Questions> findQuestionIds(List<ObjectId> questionIds) {
        // 1. questionIds集合不为空，则questionIds作为条件查询
        Query query = new Query();
        if (!CollectionUtils.isEmpty(questionIds)){
            query.addCriteria(Criteria.where("id").in(questionIds));
        }
        // 2. questionIds集合有值，则查询全部
        List<Questions> questionsList = mongoTemplate.find(query, Questions.class);
        return null;
    }

}
